package com.mine.springmvc.run;

/*
* 线程的状态
* 人有：生老病死
* 线程有：创建、就绪、运行、阻塞、死亡
*
* new 新生 start就绪状态  sleep,wait阻塞 dead 死亡
*
* 线程方法
* 优先级
* 睡眠
* join
* yield
* isAlive
* 让线程停止，设置一个标志位，让线程自己退出来
*
* 线程优先级
*
* 守护线程 线程设置为守护线程
* 线程同步
*
*
* */
public class TestThreadState {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                try {
                    System.out.println(i);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });

        Thread.State state = thread.getState();
        System.out.println(state); // new

        thread.start();
        state = thread.getState();
        System.out.println(state); // RUNNABLE

        while (state!=Thread.State.TERMINATED){
            Thread.sleep(100);
            state = thread.getState();
            System.out.println(state);
        }
    }
}
